<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Cat extends Model
{
    public $timestamps = false;



    // 查询指定栏目下的所有子孙栏目
   public function __construct() {
        parent::__construct();
        $this->cats = $this::get();
    }

    public function getTree($id=0 , $lev=0) {
               $tree = array();
        foreach($this->cats as $v) {
                    if($v['parent_id'] == $id) {
                $v['lev'] = $lev;
                $tree[] = $v;
                $tree = array_merge($tree , $this->getTree($v['cat_id'] , $lev+1));
            }
        }
        return $tree;
    }

}
